home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import caurina.transitions.Tweener;
- import flash.display.DisplayObject;
- import flash.display.DisplayObjectContainer;
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- import flash.geom.Point;
- import flash.geom.Rectangle;
-
- [Embed(source="/_assets/assets.swf", symbol="ClothingSlot")]
- public class ClothingSlot extends MovieClip
- {
-
-
- internal var _nTriggerDist:Number;
-
- internal var _pOriginalPosition:Point;
-
- internal var _nRestY:Number;
-
- internal var _nRestX:Number;
-
- internal var _pSize:Point;
-
- public var _filler:ClothingSlotFiller;
-
- internal var _nInitialY:Number;
-
- internal var _nInitialX:Number;
-
- public function ClothingSlot()
- {
- super();
- _pSize = new Point(width,height);
- _pOriginalPosition = new Point(x,y);
- }
-
- public static function extractFromStage(param1:DisplayObjectContainer) : Array
- {
- var _loc2_:int = 0;
- var _loc3_:Array = null;
- var _loc4_:DisplayObject = null;
- _loc2_ = 0;
- _loc3_ = new Array();
- _loc2_ = 0;
- while(_loc2_ < param1.numChildren)
- {
- if((_loc4_ = param1.getChildAt(_loc2_)) is ClothingSlot)
- {
- _loc3_.push(_loc4_);
- }
- _loc2_++;
- }
- return _loc3_.sortOn("name");
- }
-
- protected function onMouseMove(param1:MouseEvent) : void
- {
- var _loc2_:Number = NaN;
- var _loc3_:Number = NaN;
- _loc2_ = calcDist(mouseX,mouseY,_nRestX,_nRestY);
- if(_loc2_ < 2 * _nTriggerDist)
- {
- if(_loc2_ > _nTriggerDist)
- {
- _loc3_ = (_loc2_ - _nTriggerDist) / _nTriggerDist;
- }
- else
- {
- x = _nInitialX;
- y = _nInitialY;
- }
- }
- else
- {
- x = _nRestX;
- y = _nRestY;
- }
- }
-
- public function clean() : void
- {
- while(numChildren > 1)
- {
- if(getChildAt(0).alpha == 0)
- {
- removeChildAt(1);
- }
- else
- {
- removeChildAt(0);
- }
- }
- }
-
- public function getPart() : Part
- {
- var _loc1_:int = 0;
- _loc1_ = 0;
- while(_loc1_ < numChildren)
- {
- if(getChildAt(_loc1_) is Part)
- {
- return getChildAt(_loc1_) as Part;
- }
- _loc1_++;
- }
- return null;
- }
-
- public function setHiddenAndClickable() : void
- {
- _filler.alpha = 0;
- }
-
- public function hasPart() : Boolean
- {
- return getPart() != null;
- }
-
- public function setRest(param1:Number, param2:Number) : void
- {
- _nRestX = param1;
- _nRestY = param2;
- _nInitialX = x;
- _nInitialY = y;
- _nTriggerDist = calcDist(x,y,param1,param2);
- parent.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove,false,0,true);
- }
-
- public function slideIn() : void
- {
- var _loc1_:Part = null;
- var _loc2_:Number = NaN;
- var _loc3_:Rectangle = null;
- var _loc4_:Number = NaN;
- _loc1_ = getPart();
- if(_loc1_ != null)
- {
- Tweener.removeTweens(_loc1_,[x]);
- _loc1_.center();
- _loc2_ = _loc1_.x;
- _loc3_ = this.getBounds(stage);
- y = _pOriginalPosition.y;
- if(_loc3_.x > this.stage.stageWidth / 2)
- {
- _loc1_.x += 150;
- }
- else
- {
- _loc1_.x -= 150;
- }
- _loc4_ = 0.5 + Math.random() * 2;
- Tweener.addTween(_loc1_,{
- "x":_loc2_,
- "time":_loc4_,
- "transition":"easeoutelastic"
- });
- }
- }
-
- public function isPointInRect(param1:Number, param2:Number) : Boolean
- {
- if(param1 < x || param1 > x + _pSize.x)
- {
- return false;
- }
- if(param2 < y || param2 > y + _pSize.y)
- {
- return false;
- }
- return true;
- }
-
- protected function calcDist(param1:Number, param2:Number, param3:Number, param4:Number) : Number
- {
- return Math.sqrt((param1 - param3) * (param1 - param3) + (param2 - param4) * (param2 - param4));
- }
-
- public function pickupPart() : Part
- {
- var _loc1_:Part = null;
- var _loc2_:Point = null;
- _loc1_ = getPart();
- if(_loc1_ != null)
- {
- _loc2_ = _loc1_.parent.localToGlobal(new Point(0,0));
- _loc1_.Pose = ModelPose.DEFAULT;
- Tweener.removeTweens(_loc1_,[x,y]);
- clean();
- }
- return _loc1_;
- }
- }
- }
-